enum Color {
    Red(u8),
    Green,
    Blue,
}

impl Color {
    fn get_red_value(&self) -> Option<u8> {
        match self {
            Color::Red(r) => Some(*r),
            _ => None,
        }
    }
}

// option
fn get_optional_value(value: Option<u8>) -> u8 {
    if let Some(v) = value {
        v
    } else {
        0
    }
}

// option match 
fn get_optional_value_match(value: Option<u8>) -> Option<u8> {
    match value {
        Some(v) => Some(v),
        None => None,
    }
}

fn main() {
    let color = Color::Red(255);
    match color {
        Color::Red(r) => println!("The color is red {}",r),
        Color::Green => println!("The color is green"),
        Color::Blue => println!("The color is blue"),
    }

    let red_value = color.get_red_value();
    if let Some(r) = red_value {
        println!("The red value is {}", r);
    } else {
        println!("The color is not red");
    }

    match red_value {
        Some(r) => println!("The red value is {}", r),
        None => println!("The color is not red"),
    }

    let optional_value = Some(10);
    let value = get_optional_value(optional_value);
    println!("The value is {}", value); // 10

    let optional_value = None;
    let value = get_optional_value(optional_value);
    println!("The value is {}", value); // 0

    let optional_value = Some(10);
    let value = get_optional_value_match(optional_value);
    if let Some(v) = value {
        println!("The value is {}", v); // 10
    } else {
        println!("The value is None");
    }

    let optional_value = None;
    let value = get_optional_value_match(optional_value);
    if let Some(v) = value {
        println!("The value is {}", v); // 0
    } else {
        println!("The value is None");
    }
}
